/*****  Component, by Ben Bi <prince.bi@gmail.com>  created at: 12/23/2009 4:10:45 PM  *****/

/********   Notes:  *******
 *  Two tags need to be replaced with the module name, they are:
 *  finalClothQcTestForm
 *  FinalClothQcTestForm
 *  FinalClothQc
 */



/***** variables declartion section, begin *****/
var finalClothQcTestFormInputMode = wacFormInputMode.add;
var finalClothQcTestFormObj = {};
var finalClothQcTestFormAuditAction = {};

var finalClothQcTestFormDataStore = {items:[]};  // to store the items
var finalClothQcTestForm_goodsListCurrentPage = 1;
var finalClothQcTestForm_goodsListTotalPages = 1;

/***** variables declartion section, end *****/

/***** init section, begin *****/
$(document).ready(
    function() {
        finalClothQcTestFormAuditAction = new FinalClothQcTestFormAuditAction();

        initFinalClothQcTestFormDialog();

        initFinalClothQcTestForm();

        bindFinalClothQcTestFormEvents();
    }
);

function bindFinalClothQcTestFormEvents()
{
    $("#finalClothQcTestFormFormDialog").bind('dialogopen', function(event, ui)
    {
        initFinalClothQcTestFormData();
//        wacDebugLog("calling " + moduleName + ":" + wacModelObj.finalClothQcTestForm.name);//
    });

    $("#finalClothQcTestFormFormDialog").bind('dialogclose', function(event, ui)
    {
        $.validationEngine.closePrompt(".formError", true);
    });

    $("#finalClothQcTestForm_btnSubmit").bind('click', function (e)
    {
        submitFinalClothQcTestForm();
    });

    $("#finalClothQcTestForm_btnClose").bind('click', function (e)
    {
        $("#finalClothQcTestFormFormDialog").dialog('close');
    });

    $("#finalClothQcTestForm_btnPrev").bind('click', function (e)
    {
        if(finalClothQcTestForm_goodsListCurrentPage>1)
        {
            finalClothQcTestForm_goodsListCurrentPage--;
            if($('#finalClothQcTestForm_dispatch_order_id_hidden').val()!="")
            {
                finalClothQcTestFormRefleshStockGoodsList($('#finalClothQcTestForm_dispatch_order_id_hidden').val());
            }
        }
    });

    $("#finalClothQcTestForm_btnNext").bind('click', function (e)
    {
        if(finalClothQcTestForm_goodsListCurrentPage < finalClothQcTestForm_goodsListTotalPages)
        {
            finalClothQcTestForm_goodsListCurrentPage++;
            if($('#finalClothQcTestForm_dispatch_order_id_hidden').val()!="")
            {
                finalClothQcTestFormRefleshStockGoodsList($('#finalClothQcTestForm_dispatch_order_id_hidden').val());
            }
        }
    });

    $("#finalClothQcTestForm_btnTransfer").bind('click', function (e)
    {
        finalClothQcTestFormTransferGoods("#finalClothQcTestForm_stockGoodsList", "#finalClothQcTestForm_targetGoodsList", "qc_items");
    });


    // fix dialog div didnt remove bug, remove it by this way
    $('#appStorehouseRightPane').bind('tabsremove', function(event, ui) {
        if(ui.panel.id == "t16003")
        {
            $("div[aria-labelledby='ui-dialog-title-finalClothQcTestFormFormDialog']").remove();
            $("#finalClothQcTestFormFormDialog").remove();
        }
    });
}


function initFinalClothQcTestFormDialog()
{
//    wacDebugLog("initFinalClothQcTestFormDialog.");
    $("#finalClothQcTestFormFormDialog").dialog({
            bgiframe: true,
            modal: true,
            width: 1150,
            height: 680,
            autoOpen: false,
            buttons: {},
            zIndex: 100
        });
}

function initFinalClothQcTestForm()
{
//    wacDebugLog("initFinalClothQcTestForm");
    $("#finalClothQcTestFormForm").validationEngine();

    $.datepicker.setDefaults($.datepicker.regional['zh-CN']);
    $("#finalClothQcTestForm_qc_date").datepicker({beforeShow: function() {$('#ui-datepicker-div').maxZIndex();}});
    $("#finalClothQcTestForm_dispatch_date").datepicker({beforeShow: function() {$('#ui-datepicker-div').maxZIndex();}});
    $("#finalClothQcTestForm_goods_return_date").datepicker({beforeShow: function() {$('#ui-datepicker-div').maxZIndex();}});

    $('.wacFormContent .left, .wacFormContent input, .wacFormContent textarea, .wacFormContent select').focus(function(){
        $(this).parents('.wacFormContent').addClass("wacFormOver");
    }).blur(function(){
        $(this).parents('.wacFormContent').removeClass("wacFormOver");
    });

    $('.wacFormContentA .left, .wacFormContentA input, .wacFormContentA textarea, .wacFormContentA select').focus(function(){
        $(this).parents('.wacFormRow').addClass("wacFormOver");
    }).blur(function(){
        $(this).parents('.wacFormRow').removeClass("wacFormOver");
    });

    // init the good list css and selectable
    $('ol#finalClothQcTestForm_stockGoodsList li').hover(
        function() {
            $(this).addClass('ui-state-hover');
        },
        function() {
            $(this).removeClass('ui-state-hover');
        }
    );

    $("#finalClothQcTestForm_stockGoodsList").selectable({
        stop: function(){
//            var result = $("#finalClothQcTestForm_selectStockGoods").empty();
//            $(".ui-selected", this).each(function(){
//                var index = $("#finalClothQcTestForm_stockGoodsList li").index(this);
//                result.append(" #" + (index + 1));
//                wacDebugLog($(this).attr("goods_id") + ": " + $(this).attr("goods_number") + ": " + $(this).html());
//            });
        }
    });

}

function initFinalClothQcTestFormData()
{
    wacShowBlockUILoading("#finalClothQcTestFormFormDialog");
    $('#finalClothQcTestForm_dispatch_order_id, #finalClothQcTestForm_target_id').empty();

    var params = {"data_format" :'json'};
    if(finalClothQcTestFormInputMode == wacFormInputMode.add)
    {
        params.id = 0;
    }
    else
    {
        params.id = finalClothQcTestFormObj.id;
    }

    $.ajax({
        url: BASE_URL + "finalClothQcTestForm/getFormData",
        global: true,
        type: "GET",
        data: params,
        dataType: "json",
        success: function(jsonData){
            initFinalClothQcTestFormDataCallBack(jsonData);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            wacDebugLog("getFormData Error: " + $(this).dump()); // the options for this ajax request
        }
    });
}

function initFinalClothQcTestFormDataCallBack(jsonData)
{
   if(jsonData.info.status == wacOperationStatus.Error)
   {
       alert(jsonData.info.error_info);
   }
   else
    {
        var itemStr = "";
        finalClothQcTestFormEmptyStockGoodsList();
        if(jsonData['items']['stock_goods_items']['items']!=undefined){
            for(i=0;i<jsonData['items']['stock_goods_items']['items'].length;i++)
            {
                itemStr = finalClothQcTestFormSetupStockGoodsItemStr(jsonData['items']['stock_goods_items']['items'][i]);
                $(itemStr).appendTo("#finalClothQcTestForm_stockGoodsList");
            }
            finalClothQcTestForm_goodsListTotalPages = jsonData['items']['stock_goods_items']['totalPages'];
        }

        finalClothQcTestFormEmptyTargetGoodsList();
        for(i=0;i<jsonData['items']['target_items'].length;i++)
        {
            $(finalClothQcTestFormDataStore).data(jsonData['items']['target_items'][i].goods_id, jsonData['items']['target_items'][i].goods_id);

            itemStr = finalClothQcTestFormSetupTargetGoodsItemStr(jsonData['items']['target_items'][i], "qc_items", false);
            $(itemStr).appendTo("#finalClothQcTestForm_targetGoodsList");
        }
   }

   setupFinalClothQcTestFormDefaultValues(jsonData['items']['default']);

   wacHideBlockUI("#finalClothQcTestFormFormDialog");

//   wacDebugLog($.dump(jsonData));
}

function setupFinalClothQcTestFormDefaultValues(defaultValueObj)
{
    if(finalClothQcTestFormInputMode == wacFormInputMode.add)   // use default values
    {
        $("#finalClothQcTestForm_id").attr("value", 0);
        $('#finalClothQcTestForm_dispatch_order_id').flexbox(BASE_URL + 'dispatchOrder/GetIdCodeHashInFormat/status/audited/type/4?data_format=jsonFlexbox', {
            //            resultTemplate: '<div class="col1">{id}</div><div class="col2">{name}</div>',
            watermark: '请输入选择...',
            noResultsText : '没找到相符项!',
            width: 200,
            maxVisibleRows: 15,
            autoCompleteFirstMatch: true,
            queryDelay: 200,
            minChars: 1,
            paramName: "dispatch_order_id",
            onSelect: function() {
                $(finalClothQcTestFormDataStore).removeData();
                finalClothQcTestForm_goodsListCurrentPage = 1;
                finalClothQcTestFormEmptyTargetGoodsList();
                finalClothQcTestFormRefleshStockGoodsList(this.getAttribute('hiddenValue'));
//                wacDebugLog('You selected "' + this.value + '", ' +
//                    'which has a hidden value of ' + this.getAttribute('hiddenValue'));
            }
        });

        $('#finalClothQcTestForm_target_id').flexbox(BASE_URL + 'factory/GetFinalClothFactoryIdNameHashInFormat?types[]=6&data_format=jsonFlexbox', {
            //            resultTemplate: '<div class="col1">{id}</div><div class="col2">{name}</div>',
            watermark: '请输入选择...',
            noResultsText : '没找到相符项!',
            width: 200,
            maxVisibleRows: 15,
            autoCompleteFirstMatch: true,
            queryDelay: 200,
            minChars: 1,
            paramName: "target_id",
            onSelect: function() {
//                wacDebugLog('You selected "' + this.value + '", ' +
//                    'which has a hidden value of ' + this.getAttribute('hiddenValue'));
            }
        });

        $("#finalClothQcTestForm_stockGoodsListPageBtns").hide();
    }
    else  // use edit obj values
    {
        $('#finalClothQcTestForm_dispatch_order_id').flexbox(BASE_URL + 'dispatchOrder/GetIdCodeHashInFormat/status/audited/type/4?data_format=jsonFlexbox', {
            //            resultTemplate: '<div class="col1">{id}</div><div class="col2">{name}</div>',
            initialValue: finalClothQcTestFormObj.dispatch_order_id,
            watermark: '请输入选择...',
            noResultsText : '没找到相符项!',
            width: 200,
            maxVisibleRows: 15,
            autoCompleteFirstMatch: true,
            queryDelay: 200,
            minChars: 1,
            paramName: "dispatch_order_id",
            onSelect: function() {
                $(finalClothQcTestFormDataStore).removeData();
                finalClothQcTestForm_goodsListCurrentPage = 1;
                finalClothQcTestFormEmptyTargetGoodsList();
                finalClothQcTestFormRefleshStockGoodsList(this.getAttribute('hiddenValue'));
//                wacDebugLog('You selected "' + this.value + '", ' +
//                    'which has a hidden value of ' + this.getAttribute('hiddenValue'));
            }
        });
        $('#finalClothQcTestForm_dispatch_order_id_input').val(finalClothQcTestFormObj.dispatch_order_code);
        
        $('#finalClothQcTestForm_target_id').flexbox(BASE_URL + 'factory/GetFinalClothFactoryIdNameHashInFormat?types[]=6&data_format=jsonFlexbox', {
            //            resultTemplate: '<div class="col1">{id}</div><div class="col2">{name}</div>',
            initialValue: finalClothQcTestFormObj.target_id,
            watermark: '请输入选择...',
            noResultsText : '没找到相符项!',
            width: 200,
            maxVisibleRows: 15,
            autoCompleteFirstMatch: true,
            queryDelay: 200,
            minChars: 1,
            paramName: "target_id",
            onSelect: function() {
//                wacDebugLog('You selected "' + this.value + '", ' +
//                    'which has a hidden value of ' + this.getAttribute('hiddenValue'));
            }
        });
        $('#finalClothQcTestForm_target_id_input').val(finalClothQcTestFormObj.target_name);

        $("#finalClothQcTestForm_qc_date").attr("value", finalClothQcTestFormObj.qc_date);
        $("#finalClothQcTestForm_dispatch_date").attr("value", finalClothQcTestFormObj.dispatch_date);
        $("#finalClothQcTestForm_goods_return_date").attr("value", finalClothQcTestFormObj.goods_return_date);
        $("#finalClothQcTestForm_code").attr("value", finalClothQcTestFormObj.code);
        $("#finalClothQcTestForm_id").attr("value", finalClothQcTestFormObj.id);
        $("#finalClothQcTestForm_memo").attr("value", finalClothQcTestFormObj.memo);
    }

//    wacDebugLog($.dump(finalClothQcTestFormObj));
//    wacDebugLog($.dump(defaultValueObj));
//    wacDebugLog("finalClothQcTestFormInputMode: " + finalClothQcTestFormInputMode);

}
/***** init section, end *****/


/**************  interaction section, begin  ***************/
// audit class
function FinalClothQcTestFormAuditAction(){
    this.run = function(orderId){
        finalClothQcTestFormAudit(orderId);
    }
}

function finalClothQcTestFormAudit(id)
{
    wacShowBlockUILoading();
    var params = {
        "data_format" : 'json',
        "form_id" : id
    };

    $.ajax({
        url: BASE_URL + "finalClothQcTestForm/audit",
        global: true,
        type: "GET",
        data: params,
        dataType: "json",
        success: function(jsonData){
            finalClothQcTestFormAuditCallBack(jsonData);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            wacDebugLog("getFormData Error: " + $(this).dump()); // the options for this ajax request
        }
    });
}

function finalClothQcTestFormAuditCallBack(jsonData)
{
   if(jsonData.info.status == wacOperationStatus.Error)
   {
       wacShowTips(jsonData.info.error_info);
   }
   else
   {
       wacShowTips(jsonData.info.tips);
       $("#finalClothQcTestFormList").trigger("reloadGrid");
   }
   wacHideBlockUI();
//   wacDebugLog($.dump(jsonData));
}

function finalClothQcTestFormOpenModuleForm(moduleFormName, moduleName, inputMode, rowid)
{
    finalClothQcTestFormInputMode = inputMode;

    if(rowid === undefined){
        finalClothQcTestFormObj = {};
    }
    else
    {
        finalClothQcTestFormObj = $("#" + moduleName +"List").getRowData(rowid);
    }

    $('#'+moduleFormName).dialog('open');
}

function validateFinalClothQcTestForm()
{
    var validateFlag = true;

    if (!$("#finalClothQcTestFormForm").validationEngine({returnIsValid:true}))
    {
        validateFlag = false;
        return validateFlag;
    }

    if($("#finalClothQcTestForm_targetGoodsList li").length == 0)
    {
        wacShowTips("请输入检验货项!");
        validateFlag = false;
    }

    // validate the goods number
    
    $("#finalClothQcTestForm_targetGoodsList li").each(function(i){
//        wacDebugLog(i + " : " +$("#"+$(this).attr("id")+" :input").eq(2).val() + " : " +$("#"+$(this).attr("id")+" :input").eq(1).attr("id"));
//        wacDebugLog(i + " : " +$("#"+$(this).attr("id")+" :input").eq(9).val() + " : " +$("#"+$(this).attr("id")+" :input").eq(8).attr("id"));
//        wacDebugLog(i + " : " +$("#"+$(this).attr("id")+" :input").eq(10).val() + " : " +$("#"+$(this).attr("id")+" :input").eq(9).attr("id"));
        var goods_name = $("#"+$(this).attr("id")+" :input").eq(0).val();
        var dispatchGoodsNumber = parseFloat($("#"+$(this).attr("id")+" :input").eq(2).val());
        var qcGoodsNumber = parseFloat($("#"+$(this).attr("id")+" :input").eq(9).val());
        var dqGoodsNumber = parseFloat($("#"+$(this).attr("id")+" :input").eq(10).val());

        if(dispatchGoodsNumber != (qcGoodsNumber + dqGoodsNumber)){
            wacShowTips( "'" + goods_name + "' 的合格与不合格数目总和应等于出仓项目货物数量!");
            validateFlag = false;
            return;
        }
    })

    return validateFlag;
}

function submitFinalClothQcTestForm()
{
    if(!validateFinalClothQcTestForm()){
        return;
    }

    wacShowBlockUILoading("#finalClothQcTestFormFormDialog", "处理中...");

    var extraParams = "data_format=json";
    var submitUrl;

    if(finalClothQcTestFormInputMode == wacFormInputMode.add){
        submitUrl = BASE_URL + "finalClothQcTestForm/add";
    }
    else{
        submitUrl = BASE_URL + "finalClothQcTestForm/edit";
    }


    $.ajax({
        url: submitUrl,
//        url: BASE_URL + "test/ajaxTest" ,
        global: true,
        type: "GET",
        data: $("#finalClothQcTestFormForm").serialize() + "&" + extraParams,
        dataType: "json",
        success: function(jsonData){
            submitFinalClothQcTestFormCallBack(jsonData);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            wacDebugLog("getFormData Error: " + $(this).dump()); // the options for this ajax request
        }
    });
}

function submitFinalClothQcTestFormCallBack(jsonData)
{
   if(jsonData.info.status == wacOperationStatus.Error)
   {
       wacShowTips(jsonData.info.error_info);
   }
   else
   {
       $("#finalClothQcTestFormFormDialog").dialog('close');
       wacShowTips(jsonData.info.tips);
       $("#finalClothQcTestFormList").trigger("reloadGrid");
   }

   wacHideBlockUI("#finalClothQcTestFormFormDialog");

//   wacDebugLog($.dump(jsonData));
}

function finalClothQcTestFormTransferGoods(srcGoodsListId, targetGoodsListId, varName)
{
   $(".ui-selected", $(srcGoodsListId)).each(function(){
       if($(finalClothQcTestFormDataStore).data($(this).attr("goods_id")) === undefined)
       {
           $(finalClothQcTestFormDataStore).data($(this).attr("goods_id"), $(this).attr("goods_id"));
            var itemStr = finalClothQcTestFormSetupTargetGoodsItemStr(this, varName, true);
            $(itemStr).appendTo(targetGoodsListId);
       }
   });
}

function finalClothQcTestFormSetupTargetGoodsItemStr(objItem, varName, isFromStock)
{
   var tmpStr;
   if(isFromStock)
    {
        tmpStr = '<li class="ui-widget-content wacCursor" id="li_'+$(objItem).attr("goods_id")+'">' + $(objItem).attr("goods_name") + '><br/>';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_goods_name" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][goods_name]" value="'+$(objItem).attr("goods_name")+'">';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dispatch_order_item_id" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][dispatch_order_item_id]" value="'+$(objItem).attr("dispatch_order_item_id")+'">';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dispatch_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][goods_number]" value="'+$(objItem).attr("goods_number")+'">';
        tmpStr += '&nbsp;重量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_weight" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][weight]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;经纬密:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_density" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][density]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;布幅:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_roll" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][roll]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;横缩:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_horizontal_shrink" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][horizontal_shrink]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;直缩:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_vertical_shrink" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][vertical_shrink]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;拉斜:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_beveled" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][beveled]" value="" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;合格出货数量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_qc_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][qc_goods_number]" value="'+$(objItem).attr("goods_number")+'" class="validate[required,custom[onlyNumber]] wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;不合格退货数量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dq_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][dq_goods_number]" value="0" class="validate[required,custom[onlyNumber]] wacFormText" style="width: 35px;">';
        tmpStr += '<span class="ui-icon ui-icon-circle-minus" style="float:right" onclick="javascript: finalClothQcTestFormRemoveItem(this, '+ $(objItem).attr("goods_id") +');"></span>';
        tmpStr += '</li>';
    }
    else{
        tmpStr = '<li class="ui-widget-content wacCursor" id="li_'+$(objItem).attr("goods_id")+'">' + $(objItem).attr("goods_name") + '><br/>';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_goods_name" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][goods_name]" value="'+$(objItem).attr("goods_name")+'">';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dispatch_order_item_id" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][dispatch_order_item_id]" value="'+$(objItem).attr("dispatch_order_item_id")+'">';
        tmpStr += '<input type="hidden" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dispatch_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][goods_number]" value="'+$(objItem).attr("goods_number")+'">';
        tmpStr += '&nbsp;重量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_weight" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][weight]" value="'+$(objItem).attr("weight")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;经纬密:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_density" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][density]" value="'+$(objItem).attr("density")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;布幅:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_roll" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][roll]" value="'+$(objItem).attr("roll")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;横缩:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_horizontal_shrink" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][horizontal_shrink]" value="'+$(objItem).attr("horizontal_shrink")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;直缩:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_vertical_shrink" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][vertical_shrink]" value="'+$(objItem).attr("vertical_shrink")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;拉斜:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_beveled" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][beveled]" value="'+$(objItem).attr("beveled")+'" class="wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;合格出货数量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_qc_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][qc_goods_number]" value="'+$(objItem).attr("qc_goods_number")+'" class="validate[required,custom[onlyNumber]] wacFormText" style="width: 35px;">';
        tmpStr += '&nbsp;不合格退货数量:&nbsp;<input type="text" id="finalClothQcTestForm_id_' + $(objItem).attr("goods_id") +'_dq_goods_number" name="'+ varName +'[id_' + $(objItem).attr("goods_id") + '][dq_goods_number]" value="'+$(objItem).attr("dq_goods_number")+'" class="validate[required,custom[onlyNumber]] wacFormText" style="width: 35px;">';
        tmpStr += '<span class="ui-icon ui-icon-circle-minus" style="float:right" onclick="javascript: finalClothQcTestFormRemoveItem(this, '+ $(objItem).attr("goods_id") +');"></span>';
        tmpStr += '</li>';
    }
    return tmpStr;
}

function finalClothQcTestFormRemoveItem(tagObj, goodId)
{
    $(tagObj).parent().remove();
    $(finalClothQcTestFormDataStore).removeData(goodId);
}

function finalClothQcTestFormSetupStockGoodsItemStr(objItem)
{
    var tmpStr = '<li class="ui-widget-content wacCursor" goods_id="' + $(objItem).attr("goods_id") +'" goods_number="' + $(objItem).attr("goods_number")+' "';
        tmpStr += ' goods_name="' + $(objItem).attr("goods_name") + ' " goods_number_unit_code_name="' + $(objItem).attr("goods_number_unit_code_name")+'"';
        tmpStr += ' dispatch_order_item_id="' + $(objItem).attr("id")+'"';
        tmpStr += ' >';
        tmpStr += $(objItem).attr("goods_name") + "&nbsp;" + $(objItem).attr("goods_number") + "&nbsp;" + $(objItem).attr("goods_number_unit_code_name") +'</li>';
    return tmpStr;
}

function finalClothQcTestFormRefleshStockGoodsList(id)
{
    wacShowBlockUILoading("#finalClothQcTestForm_stockGoodsZone", "装载中...");

    var submitUrl;
    var params = {
        "data_format" : 'json',
        "searchOper" : 'eq',
        "searchField" : 'parent_id',
        "searchString" : id,
        "rows" : 10,
        "page" : finalClothQcTestForm_goodsListCurrentPage
    };

    submitUrl = BASE_URL + "dispatchOrderItem/GetList";
//    submitUrl = BASE_URL + "test/ajaxTest";
    $.ajax({
        url: submitUrl,
        global: true,
        type: "GET",
        data: params,
        dataType: "json",
        success: function(jsonData){
            finalClothQcTestFormRefleshStockGoodsListCallBack(jsonData);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            wacDebugLog("getFormData Error: " + $(this).dump()); // the options for this ajax request
        }
    });
}

function finalClothQcTestFormRefleshStockGoodsListCallBack(jsonData)
{
    if(jsonData.info.status == wacOperationStatus.Error)
    {
        wacShowTips(jsonData.info.error_info);
    }
    else
    {
        finalClothQcTestForm_goodsListTotalPages = jsonData.totalPages;
        if(finalClothQcTestForm_goodsListTotalPages > 1){
            $("#finalClothQcTestForm_stockGoodsListPageBtns").show();
        }
        finalClothQcTestFormEmptyStockGoodsList();
        for(i=0;i<jsonData['items'].length;i++)
        {
            var itemStr = finalClothQcTestFormSetupStockGoodsItemStr(jsonData['items'][i]);
            $(itemStr).appendTo("#finalClothQcTestForm_stockGoodsList");
        }
//        wacShowTips(jsonData.info.tips);
    }

    wacHideBlockUI("#finalClothQcTestForm_stockGoodsZone");
}

function finalClothQcTestFormEmptyStockGoodsList()
{
    $("#finalClothQcTestForm_stockGoodsZone li").remove();
}

function finalClothQcTestFormEmptyTargetGoodsList()
{
    $("#finalClothQcTestForm_targetGoodsZone li").remove();
}
/**************  interaction section, end  ***************/